import location from '@/api/location'

const state = {
  all: []
}

const actions = {
  addToCart ({commit}, locations) {
    commit('add_to_cart', locations.id)
  },
  getAllLocations ({commit}) {
    location.getLocations(locations => {
      commit('receive_locations', locations)
    })
  }
}

const mutations = {
  receive_locations (state, locations) {
    state.all = locations
  },
  add_to_cart (state, locationsId) {
    state.all.find(p => p.id === locationsId).inventory--
  }
}
const getters = {
  allLocations (state) {
    return state.all
  }
}
export default {
  state,
  actions,
  mutations,
  getters
}
